/**
 * @a https://leetcode.cn/problems/zigzag-conversion/
 */

#include "common.h"

class Solution
{
public:
    string convert(string s, int numRows)
    {
        if(numRows == 1) return s;
        string layer_str[1005];
        int mod = numRows * 2 - 1, sz = s.size();

        int inc_dec_flag = -1, layer = 0;
        for(int i = 0 ; i < sz; ++i)
        {
            if(i % (numRows - 1) == 0) inc_dec_flag = -inc_dec_flag;
            layer_str[layer].push_back(s[i]);
            layer += inc_dec_flag;
        }
        string ret;
        for(int i = 0; i < numRows; ++i){
            ret += layer_str[i];
        }
        return ret;
    }
};